layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(addOrUpdateRole)", function (data) {
        let url = ctx + "/role/save";
        if (data.field.id) {
            url = ctx + "/role/update";
        }
        $.post(url, data.field, function (data) {
            if (data.code === 200) {
                layer.msg("操作成功", function () {
                    // 关闭弹出层
                    layer.closeAll("iframe");
                    // 刷新父页面
                    parent.location.reload();
                });
            } else {
                layer.msg(data.msg(), {icon: 6});
            }
        });

        return false;
    });

    /**
     * 关闭弹出层
     */
    $("#closeBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执⾏关闭
    });


});